﻿<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script>
//申请磁盘配额
function getQuota(){
    var size = document.getElementById("capacity").value; 
    window.webkitStorageInfo.requestQuota(PERSISTENT,size,
    //申请磁盘配额成功时执行的回调函数
    function(grantedBytes){
        var text="申请磁盘配额成功<br>磁盘配额尺寸:"
        var strBytes,intBytes;
        if(grantedBytes>=1024*1024*1024){
            intBytes=Math.floor(grantedBytes/(1024*1024*1024));
            text+=intBytes+"GB ";
            grantedBytes=grantedBytes%(1024*1024*1024);
        }
        if(grantedBytes>=1024*1024){
            intBytes=Math.floor(grantedBytes/(1024*1024));
            text+=intBytes+"MB ";
            grantedBytes=grantedBytes%(1024*1024);
        }
        if(grantedBytes>=1024){
            intBytes=Math.floor(grantedBytes/1024);
            text+=intBytes+"KB ";
            grantedBytes=grantedBytes%1024;
        }
        text+=grantedBytes+"Bytes";
        document.getElementById("result").innerHTML = text;
    },
    //申请磁盘配额失败时执行的回调函数
    errorHandler);
}
function errorHandler(e) {
    switch (e.code) {
        case FileError.QUOTA_EXCEEDED_ERR:
            console.log('文件系统所使用的存储空间的尺寸超过磁盘限额控制中指定的空间尺寸');
            break;
        case FileError.NOT_FOUND_ERR:
            console.log('未找到文件或目录');
            break;
        case FileError.SECURITY_ERR:
            console.log( '操作不当引起安全性错误');
            break;
        case FileError.INVALID_MODIFICATION_ERR:
            console.log('对文件或目录所指定的操作不能被执行');
            break;
        case FileError.INVALID_STATE_ERR:
            console.log('指定的状态无效');
    };
}

</script>
</head>
<body>
<form>      
<input type="text" id="capacity" value="1024">       
<input type="button" value="申请磁盘配额" onclick="getQuota()">     
</form>     
<output id="result" ></output>   
</body>
</html> 
